<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
    <!--<![endif]&ndash;&gt;-->
    <style>
        .menudiv .layui-input-inline,.buttondiv .layui-input-inline {
            float: left;
            width: 450px !important;
            margin-right: 10px;
        }
        .buttondiv{
            display: none;
        }

    </style>
</head>
<body >
<div class="layui-fluid" id="flowDiv" onload="onLoad()" >
    <div class="zTreeBackground left" style="float: left;width:250px;height:450px;">
        <div class="titlediv">
            <p style="text-align:right;background-color:white;line-height: 30px">
                组织信息<i class="layui-icon layui-icon-refresh" style="margin-left: 36%" onclick="loadTree()"></i>&ensp;&ensp;
            </p>

        </div>
        <div class="searchdiv" >
            <div class="layui-input-inline" style="width:100%">
                <input type="text" id="keyword" name="keyword" autocomplete="off" class="layui-input" placeholder="请输入名称"/>
                <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="query()"></i>
            </div>
        </div>
        <div class="ztreediv" id="ztreediv" style="overflow:auto;height: 400px;">
            <div class="ztreeuldiv">
                <ul id="treeStructure" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="zTreeBackground right" style="float: left;width:75%;">
		<div class="layui-inline">
            <label class="layui-form-label" style="width: 60px !important;">用户名</label>
            <div class="layui-input-inline">
                <input type="text" id="name" class="layui-input">
            </div>
            <div class="layui-input-inline">
                <button class="layui-btn layui-btn-normal" style="margin-left: 15px" onclick="loadTable()"><i class="layui-icon">&#xe615;</i>查询</button> 
				<button type="button" style="margin-left: 15px" class="layui-btn layui-btn-normal" onclick="unbindorgrole()"><i class="layui-icon">&#xe608;</i>删除</button>
            </div>
            
        </div>
        <div class="menudiv">
            <div class="layui-card-body ">
                <table class="layui-table layui-form" id="datatable" lay-filter="data-table">
                </table>
            </div>

        </div>
    </div>
    <!--<div class="layui-row layui-col-space15">-->

    <!--<div class="layui-col-md4 treetool" id="flowDiv" onload="onLoad()">-->

    <!--</div>-->
    <!--<div class="layui-col-md8">-->
    <!--<input type="button" value="获取选中项" onclick="getSelectNode()"/>-->
    <!--<input type="button" value="获取check项" onclick="getCheckNode()"/>-->
    <!--<input type="button" value="刷新选中项" onclick="refreshSelectNode()"/>-->
    <!--</div>-->
    <!--</div>-->
</div>
</body>
<SCRIPT type="text/javascript">
    var zTreeObj,roleid;
    var form;
    var table;
    var orgId;
    var orgName;
    var positionMap,sexMap,typeMap,stateMap;
    var type;
    var initFlag=true;
    layui.use(['form', 'layer'], function() {
        form = layui.form;
        layer = layui.layer;
        table = layui.table;


    });
    $(function(){
        positionMap=getDic("UserPosition");
        sexMap=getDic("UserSex");
        typeMap=getDic("UserType");
        stateMap=getDic("UserState");
        loadTree();
        // loadTable();
        //单击行勾选checkbox事件
        $(document).on("click",".layui-table-body table.layui-table tbody tr", function () {
            var index = $(this).attr('data-index');
            var tableBox = $(this).parents('.layui-table-box');
            //存在固定列
            if (tableBox.find(".layui-table-fixed.layui-table-fixed-l").length>0) {
                tableDiv = tableBox.find(".layui-table-fixed.layui-table-fixed-l");
            } else {
                tableDiv = tableBox.find(".layui-table-body.layui-table-main");
            }
            var checkCell = tableDiv.find("tr[data-index=" + index + "]").find("td div.laytable-cell-checkbox div.layui-form-checkbox i");
            if (checkCell.length>0) {
                checkCell.click();
            }
        });

        $(document).on("click", "td div.laytable-cell-checkbox div.layui-form-checkbox", function (e) {
            e.stopPropagation();
        });

    });


    //查询字典
    function getDic(code){
        var map=new Map();
        publicAjax ("post","/infdictitem/selectInfdictitemByInfdictsortCode?code="+code,{},false
            ,null,function (r) {
                var data=r.data;
                for(var i=0;i<data.length;i++){
                    map.set(data[i].code,data[i].name);
                }
            });
        return map;
    }





    /**
     * 左侧树设置
     * @type {{check: {enable: boolean}, data: {simpleData: {enable: boolean, idKey: string, pIdKey: string, isParent: string, rootPid: number}}, callback: {beforeClick: zTreeBeforeClick, onClick: zTreeOnClick}}}
     */
    var setting = {
        view: {
            dblClickExpand: false,
            showLine: true,
            selectedMulti: false,
            nameIsHTML: true
        },
        check: {
            enable: false,
            chkboxType:  { "Y": "", "N": "" }
        },
        edit:{
            enable: false,
        },
        // async: {
        //     enable: true,
        //     url: "./sysmenu/selectMenuByPid",
        //     dataFilter: formatedata,
        //     autoParam: ["id"]
        // },
        data: {
            simpleData: {
                enable: true,
                idKey:"id",
                pIdKey:"parentId",
                isParent:"parent",
                rootPid:-1
            },
            key: {
                url: "xUrl",
                icon:"xIcon"
            }
        },
        callback: {
            // beforeClick: zTreeBeforeClick,
            onClick: zTreeOnClick
        }
    };


    <!-- 高亮显示查询开始 -->
    /**
     * 搜索树，高亮显示并展示【模糊匹配搜索条件的节点s】
     * @param treeId
     * @param searchConditionId     搜索条件Id
     * @param flag                  需要高亮显示的节点标识
     */
    function query11() {
        //<1>.搜索条件
        var searchCondition = $('#keyword').val();
        //<2>.得到模糊匹配搜索条件的节点数组集合
        var highlightNodes = new Array();
        if(searchCondition != "") {
            var treeObj = zTreeObj;
            highlightNodes = treeObj.getNodesByParamFuzzy("name", searchCondition, null);
        }
        //<3>.高亮显示并展示【指定节点s】
        highlightAndExpand_ztree( highlightNodes, searchCondition, false);
    }

    /**
     * 高亮显示并展示【指定节点s】
     * @param treeId
     * @param highlightNodes 需要高亮显示的节点数组
     * @param flag           需要高亮显示的节点标识
     */
    function highlightAndExpand_ztree(highlightNodes, tx, flag) {
        var treeObj = zTreeObj;
        //<1>. 先把全部节点更新为普通样式
        var treeNodes = treeObj.transformToArray(treeObj.getNodes());
        for(var i = 0; i < treeNodes.length; i++) {
            treeNodes[i].highlight = false;
            treeObj.updateNode(treeNodes[i]);
            // var t = treeNodes[i].name;
            //  t = t.replace("<span style='background-color: yellow;color:red'>", '');
            //  t = t.replace("</span>", '');
            //  console.log(t+'---------');
            // treeNodes[i].name = t;
        }
        //<2>.收起树, 只展开根节点下的一级节点
        close_ztree();
        //<3>.把指定节点的样式更新为高亮显示，并展开
        if(highlightNodes != null) {
            for(var i = 0; i < highlightNodes.length; i++) {
                if(flag != null && flag != "") {
                    if(highlightNodes[i].flag == flag) {
                        //高亮显示节点，并展开
                        highlightNodes[i].highlight = true;
                        treeObj.updateNode(highlightNodes[i]);
                        //高亮显示节点的父节点的父节点....直到根节点，并展示
                        var parentNode = highlightNodes[i].getParentNode();
                        var parentNodes = getParentNodes_ztree( parentNode);
                        treeObj.expandNode(parentNodes, true, false, true);
                        treeObj.expandNode(parentNode, true, false, true);
                    }
                } else {
                    //高亮显示节点，并展开
                    //highlightNodes[i].checked = true;
                    var t = highlightNodes[i].name;
                    // t = t.replace(eval("/" + tx + "/gi"), "<span style='background-color: yellow;color:red'>" + tx + "</span>");
                    highlightNodes[i].name = t;
                    treeObj.updateNode(highlightNodes[i]);
                    //高亮显示节点的父节点的父节点....直到根节点，并展示
                    var parentNode = highlightNodes[i].getParentNode();
                    var parentNodes = getParentNodes_ztree( parentNode);
                    treeObj.expandNode(parentNodes, true, false, true);
                    treeObj.expandNode(parentNode, true, false, true);
                }
            }
        }
    }

    /**
     * 递归得到指定节点的父节点的父节点....直到根节点
     */
    function getParentNodes_ztree( node) {
        if(node != null) {
            var treeObj =treeObj;
            var parentNode = node.getParentNode();
            return getParentNodes_ztree( parentNode);
        } else {
            return node;
        }
    }

    /**
     * 收起树：只展开根节点下的一级节点
     * @param treeId
     */
    function close_ztree() {
        var treeObj = zTreeObj;
        var nodes = treeObj.transformToArray(treeObj.getNodes());
        var nodeLength = nodes.length;
        for(var i = 0; i < nodeLength; i++) {
            // if(nodes[i].id == '0') {
            //     //根节点：展开
            //     treeObj.expandNode(nodes[i], true, true, false);
            // } else {
            //非根节点：收起
            treeObj.expandNode(nodes[i], false, true, false);
        }
        // }
    }
    <!-- 高亮显示查询结束 -->



    function query() {
        var keyword = $("#keyword").val();
        if (keyword === "") {
            //显示上次搜索后背隐藏的结点
            zTreeObj.getNodesByParam("isHidden", true);
            zTreeObj.showNodes(nodes);
            return;
        }

        var zTree = zTreeObj;
        var allNodes = zTree.transformToArray(zTree.getNodes());
        zTree.hideNodes(allNodes);    //当开始搜索时，先将所有节点隐藏

        var nodeList = zTree.getNodesByParamFuzzy('name', keyword, 0);    //通过关键字模糊搜索
        var arr = new Array();
        for (var i = 0; i < nodeList.length; i++) {
            arr = $.merge(arr, nodeList[i].getPath());    //找出所有符合要求的叶子节点的路径
        }
        zTree.showNodes($.unique(arr));    //显示所有要求的节点及其路径节点
        zTree.expandAll(true);    //展开路径
    }




    /**
     * 点击触发
     * @param event
     * @param treeId
     * @param treeNode
     */
    function zTreeOnClick(event, treeId, treeNode) {
        orgId=treeNode.id;
        //根据树的点击确定父级id、name
        orgName=treeNode.name;
        type=treeNode.type;
        loadTable();
        initFlag=false;
    }

    //加载右边表格
    function loadTable(){
        layui.use(['laydate','form','table'], function(){
            var laydate = layui.laydate;
            table = layui.table;
            table.render({
                elem: '#datatable',
                size: 'sm',
                method: 'post',
                height: 'full-110',
                url: publicUrl+'/orgPerson/selectAllOrgPersonNoRoleOrHasRole', //stationId='+window.parent.window.parentId,//8AE7DECA-8E41-4FAB-8B30-9FD1B0B7FA33,78A9E5D8-20FB-4436-BBE8-A25EAC38D056
                request: {
                    limitName: 'pageSize',
                    pageName: "pageIndex"
                },
                headers: {"Authorization":getData("Authorization")},
                response: {
                    statusCode: 2000
                },where:{
                    flag: 2,
                    orgId : orgId,
                    roleId: roleid,
					name:$("#name").val()
                },
                parseData: function(res){ //res 即为原始返回的数据
                    return formatTableParseData(res);
                }
                ,cols: [[
                    {
                        type: 'checkbox',
                        width: 50,
                        align: 'center'
                    },
                    {
                        type: 'numbers',
                        title: '序号',
                        width: 60,
                        align: 'center'
                    },
                    {
                        field: 'loginName',
                        title: '登录名',
                        width: "18%",
                        align: 'center'
                    },
                    {
                        field: 'name',
                        title: '用户名',
                        width: "14%",
                        align: 'center'
                    },
                    {
                        field: 'sexy',
                        title: '性别',
                        width: "8%",
                        align: 'center',
                        templet: function(d) {
                            return sexMap.get(d.sexy+"");
                        }
                    },
                    {
                        field: 'title',
                        title: '职位',
                        width: "15%",
                        align: 'center',
                        templet: function(d) {
                            return positionMap.get(d.title+"");
                        }
                    },
                    /*{
                        field: 'type',
                        title: '类型',
                        width: "10%",
                        align: 'center',
                        templet: function(d) {
                            return stateMap.get(d.type+"");
                        }
                    },*/
                    {
                        field: 'state',
                        title: '状态',
                        width: "10%",
                        align: 'center',
                        templet: function(d) {
                            return stateMap.get(d.state+"");
                        }
                    },
                    {
                        field: 'phone',
                        title: '电话',
                        width: "16%",
                        align: 'center'
                    }
                ]],
                page: true
            });
            // //监听行双击事件
            table.on('rowDouble(data-table)', function(obj){
                show(obj);
            });
        });


    }
    /* *
     * @Author bxf
     * @Description 初始化传值
     * @Date 16:49 2019/8/23
     * @param null
     * @return
     */
    function inint(data){
        roleid = data.id;
    }



    /**
     * 加载左侧树
     */
    function loadTree(keyWord){
        publicAjax ("post","/orgPerson/selectOrgTree",{},null,null,function (r) {
            var jsondata = r.data;
            zTreeObj = $.fn.zTree.init($("#treeStructure"), setting, changeIcon(jsondata));
            var treeObj = zTreeObj;
            var nodes = treeObj.getNodes();
            if (nodes.length>0) {
                for (var i = 0; i < nodes.length; i++) {
                    treeObj.expandNode(nodes[i], true, false, false);
                }
                //页面加载时，默认点击第一个节点
                if(initFlag){
                    zTreeObj.selectNode(nodes[0]);//选择点
                    zTreeObj.setting.callback.onClick(null, zTreeObj.setting.treeId, nodes[0]);//调用事件
                }
            }
        });
    }


    //刷新表格，必须要有参数提交，否则会不刷新
    function reloadTable(){
        table.reload('datatable', {});
    }

    /**
     * 添加按钮
     */
    function unbindorgrole(){
        //获取选中项
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length<1){
            layer.alert("请至少选择一项信息！");
            return false;
        }
        var ids = new Array();
        for(var i=0;i<obj.data.length;i++){
            ids.push(obj.data[i].id);
        }
        var result;
        publicAjax (null,'orgrole/deleteRoleAndPerson',{'roleid':roleid,'personids':ids.join(",")},false,null,function (r) {
            if(r.code==2000){
                laysuccess("删除成功",null);
                reloadTable();
                parent.loadTable();//刷新主页面
                result = r;
            }else{
                layerror("删除失败",null);
                result = r;
            }
        });
    }

    function isEmpty(value) {
        if (value == null || this.trim(value) == "") {
            return true;
        }
        return false;
    }



</SCRIPT>
</html>